﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace WebApplication2
{
    public class SQLHelper
    {
        private string constr = "uid=sa;password=7758258zx;database=Student_db";
        private SqlConnection con;

        public SQLHelper()
        {
            con = new SqlConnection(constr);
        }
        public DataSet Get(string sql,SqlParameter[] pars)
        {
            DataSet d = null;
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(pars);
                SqlDataAdapter adapter = new SqlDataAdapter(com);
                adapter.Fill(d);
            }
            catch (Exception e)
            {

                Console.WriteLine(e.Message);
            }
            finally
            {
                con.Close();
            }
            return d;
        }
        public int Rent(string sql ,SqlParameter [] pars)
        {
            int result = -1;
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(pars);
                result = com.ExecuteNonQuery();
            }
            catch (Exception e)
            {

                Console.WriteLine(e.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
    }
}